package clone;

import com.alibaba.fastjson.JSON;
import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import domain.Student;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.collections.CollectionUtils;
import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;
import vo.PersonalSceneryDTO;

import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.stream.Collectors;

public class testMain {
    public static void main(String[] args) throws CloneNotSupportedException, InvocationTargetException, IllegalAccessException {
        String ss = "[{\"imageUrl\":\"7cb2441f29b69c8b2b1772e280fc30fab4855ac8881880a7.png\",\"issueDate\":\"2018-08-08 22:04:48.0\",\"likeCount\":\"0\",\"pkMileageSceneryId\":\"1166\",\"sceneryTitle\":\"？¤a？？？\",\"userHeadImg\":\"4a6ca8e79298d50818933a9fb3c25051f1389133b7b1c1c13e145c2f9078de15.bmp\",\"userLikeFlag\":\"N\",\"userName\":\"ff\"},{\"imageUrl\":\"7cb2441f29b69c8b2b1772e280fc30fab4855ac8881880a7.png\",\"issueDate\":\"2018-08-08 21:54:20.0\",\"likeCount\":\"0\",\"pkMileageSceneryId\":\"1165\",\"sceneryTitle\":\"？¤a？？？\",\"userHeadImg\":\"4a6ca8e79298d50818933a9fb3c25051f1389133b7b1c1c13e145c2f9078de15.bmp\",\"userLikeFlag\":\"N\",\"userName\":\"ff\"},{\"issueDate\":\"2018-08-08 21:51:11.0\",\"pkMileageSceneryId\":\"1164\",\"sceneryTitle\":\"？¤a？？？\"},{\"imageUrl\":\"7cb2441f29b69c8b83c1b6b7627ee4b94c267385daf8e519.png\",\"issueDate\":\"2018-08-06 19:33:56.0\",\"likeCount\":\"0\",\"pkMileageSceneryId\":\"1163\",\"sceneryTitle\":\"太美\",\"userHeadImg\":\"4a6ca8e79298d50818933a9fb3c25051f1389133b7b1c1c13e145c2f9078de15.bmp\",\"userLikeFlag\":\"N\",\"userName\":\"ff\"},{\"imageUrl\":\"7cb2441f29b69c8b2b1772e280fc30fab4855ac8881880a7.png\",\"issueDate\":\"2018-08-01 16:17:05.0\",\"likeCount\":\"0\",\"pkMileageSceneryId\":\"1160\",\"sceneryTitle\":\"ceshi\",\"userHeadImg\":\"4a6ca8e79298d50818933a9fb3c25051f1389133b7b1c1c13e145c2f9078de15.bmp\",\"userLikeFlag\":\"N\",\"userName\":\"ff\"},{\"imageUrl\":\"7cb2441f29b69c8b2b1772e280fc30fab4855ac8881880a7.png\",\"issueDate\":\"2018-08-01 15:09:14.0\",\"likeCount\":\"0\",\"pkMileageSceneryId\":\"1161\",\"routeName\":\"衡水-廊坊\",\"sceneryTitle\":\"？¤a？？？\",\"userHeadImg\":\"4a6ca8e79298d50818933a9fb3c25051f1389133b7b1c1c13e145c2f9078de15.bmp\",\"userLikeFlag\":\"N\",\"userName\":\"ff\"},{\"imageUrl\":\"7cb2441f29b69c8b2b1772e280fc30fab4855ac8881880a7.png\",\"issueDate\":\"2018-07-28 16:14:50.0\",\"likeCount\":\"0\",\"pkMileageSceneryId\":\"1159\",\"routeName\":\"tianjin-beijing\",\"sceneryTitle\":\"ceshi\",\"userHeadImg\":\"4a6ca8e79298d50818933a9fb3c25051f1389133b7b1c1c13e145c2f9078de15.bmp\",\"userLikeFlag\":\"N\",\"userName\":\"ff\"},{\"imageUrl\":\"7cb2441f29b69c8b2b1772e280fc30fab4855ac8881880a7.png\",\"issueDate\":\"2018-07-28 16:13:04.0\",\"likeCount\":\"0\",\"pkMileageSceneryId\":\"1158\",\"routeName\":\"衡水-廊坊\",\"sceneryTitle\":\"ceshi\",\"userHeadImg\":\"4a6ca8e79298d50818933a9fb3c25051f1389133b7b1c1c13e145c2f9078de15.bmp\",\"userLikeFlag\":\"N\",\"userName\":\"ff\"},{\"imageUrl\":\"7cb2441f29b69c8b2b1772e280fc30fab4855ac8881880a7.png\",\"issueDate\":\"2018-07-28 15:47:50.0\",\"likeCount\":\"0\",\"pkMileageSceneryId\":\"1157\",\"routeName\":\"衡水-廊坊\",\"sceneryTitle\":\"？¤a？？？\",\"userHeadImg\":\"4a6ca8e79298d50818933a9fb3c25051f1389133b7b1c1c13e145c2f9078de15.bmp\",\"userLikeFlag\":\"N\",\"userName\":\"ff\"},{\"imageUrl\":\"7cb2441f29b69c8b2b1772e280fc30fab4855ac8881880a7.png\",\"issueDate\":\"2018-07-28 15:47:06.0\",\"likeCount\":\"0\",\"pkMileageSceneryId\":\"1156\",\"sceneryTitle\":\"？¤a？？？\",\"userHeadImg\":\"4a6ca8e79298d50818933a9fb3c25051f1389133b7b1c1c13e145c2f9078de15.bmp\",\"userLikeFlag\":\"N\",\"userName\":\"ff\"}]";
        List<PersonalSceneryDTO> list = JSON.parseArray(ss, PersonalSceneryDTO.class);
        Map map = list.stream().collect(Collectors.groupingBy(s->{
            return s.getIssueDate().split(" ")[0].split("-")[0];
        },Collectors.groupingBy(s->{ return s.getIssueDate().split(" ")[0].split("-")[1];},Collectors.toList())));
        List ls = new ArrayList();
        map.forEach((k,v)->{
            List ls2 = new ArrayList();
            Map map1 = new HashMap();
            map1.put("year",k);
            ((Map)v).forEach((k2,v2)->{
                Map map2 = new HashMap();
                map2.put("month",k2);
                map2.put("monthVal",v2);
                ls2.add(map2);
            });
            map1.put("yearVal",ls2);
            ls.add(map1);
        });
        System.out.println(JSON.toJSONString(ls));
    }
}
